﻿
using AutoMapper;
using EFEntity;
using Iservices;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Services
{
    public class config_major_kindServices : Iconfig_major_kind
    {
        private readonly MyDbContext dbContext;
        private readonly IMapper mapper;


        public config_major_kindServices(MyDbContext DbContext, IMapper mapper)
        {
            dbContext = DbContext;
            this.mapper = mapper;
        }
        public async Task<int> Add(config_major_kind c)
        {
           
            Econfig_major_kind c2 = mapper.Map<Econfig_major_kind>(c);
            dbContext.Configs.Add(c2);
            return await dbContext.SaveChangesAsync();
        }


        public async Task<int> Del(int id)
        {
            int result = 0;
            Econfig_major_kind s = dbContext.Configs.Find(id);
            dbContext.Configs.Remove(s);
            result = await dbContext.SaveChangesAsync();
            return result;
        }

       

        public async Task< List<config_major_kind>> SelectAll()
        {
            List<Econfig_major_kind> list = new List<Econfig_major_kind>();
            await Task.Run(() => {
                list = dbContext.Configs.ToList();
            });
            List<config_major_kind> list2 = mapper.Map<List<config_major_kind>>(list);
            return list2;
        }

       
    }
}
